<route lang="json5">
{
  style: {
    navigationStyle: 'default',
    navigationBarTitleText: '注册',
  },
}
</route>
<template>
  <view ml mr>
    <uv-form
      ref="registerForm"
      label-position="top"
      label-width="100rpx"
      :model="registerCmd"
      :rules="rules"
    >
      <uv-form-item label="用户名" prop="identifier" borderBottom>
        <uv-input type="text" placeholder="USERNAME" v-model="registerCmd.identifier"></uv-input>
      </uv-form-item>
      <uv-form-item label="密码" prop="credential" borderBottom>
        <uv-input
          :password="!passwordVisible"
          placeholder="PASSWORD"
          v-model="registerCmd.credential"
        >
          <template #suffix>
            <uv-icon
              v-if="passwordVisible"
              name="eye-fill"
              @click="passwordVisible = false"
            ></uv-icon>
            <uv-icon v-else name="eye-off" @click="passwordVisible = !passwordVisible"></uv-icon>
          </template>
        </uv-input>
      </uv-form-item>
      <!--      <uv-form-item label="手机号" prop="phoneNumber" borderBottom>-->
      <!--        <uv-input-->
      <!--          type="number"-->
      <!--          placeholder="PHONENUMBER"-->
      <!--          v-model="registerCmd.phoneNumber"-->
      <!--        ></uv-input>-->
      <!--      </uv-form-item>-->
      <!--      <uv-form-item label="邮箱" prop="email" borderBottom>-->
      <!--        <uv-input type="text" placeholder="EMAIL" v-model="registerCmd.email"></uv-input>-->
      <!--      </uv-form-item>-->
      <uv-button
        type="primary"
        text="注册"
        customStyle="margin-top: 10px"
        @click.stop="doRegister"
      ></uv-button>
      <!--      <view mt w-full>-->
      <!--        &lt;!&ndash; @unocss-skip-start&ndash;&gt;-->
      <!--        <uv-text-->
      <!--          text="已有账号? 点击登录 >>"-->
      <!--          @click="toLogin"-->
      <!--          algin="center"-->
      <!--          decoration="underline"-->
      <!--        ></uv-text>-->
      <!--        &lt;!&ndash; @unocss-skip-end&ndash;&gt;-->
      <!--      </view>-->
    </uv-form>
  </view>
</template>

<script setup lang="ts">
import { registerAPI } from '@/service/auth/auth'
import { loadRules } from '@/pages/register/rules'
import { goBack } from '@/utils/route'
import { showSuccess } from '@/utils/toast'
import type { RegisterCmd } from '@/service/auth/type'

const registerForm = ref<any>(null)
const passwordVisible = ref(false)
const registerCmd = ref<RegisterCmd>({
  authTypeCode: 'PASSWORD',
  identifier: '',
  credential: '',
})
const rules = ref(loadRules())
const doRegister = async () => {
  const result = await registerAPI(registerCmd.value)
  if (result.code === 0) {
    showSuccess('注册成功', {
      success: () => {
        setTimeout(() => {
          goBack(getCurrentPages())
        }, 1000)
      },
    })
  }
}
</script>

<style scoped lang="scss"></style>
